package schoolWork;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StudentInfoApp extends JFrame {
    private JTextField nameTextField;
    private JRadioButton maleRadioButton;
    private JRadioButton femaleRadioButton;
    private JCheckBox mathCheckBox;
    private JCheckBox scienceCheckBox;
    private JCheckBox englishCheckBox;
    private JTextArea infoTextArea;

    public StudentInfoApp() {
        setTitle("Student Information");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        nameTextField = new JTextField(20);

        maleRadioButton = new JRadioButton("Male");
        femaleRadioButton = new JRadioButton("Female");
        ButtonGroup genderGroup = new ButtonGroup();
        genderGroup.add(maleRadioButton);
        genderGroup.add(femaleRadioButton);

        mathCheckBox = new JCheckBox("Math");
        scienceCheckBox = new JCheckBox("Science");
        englishCheckBox = new JCheckBox("English");

        JButton submitButton = new JButton("Submit");
        submitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                displayStudentInfo();
            }
        });

        infoTextArea = new JTextArea(10, 30);

        JPanel panel = new JPanel();
        panel.add(new JLabel("Name: "));
        panel.add(nameTextField);
        panel.add(new JLabel("Gender: "));
        panel.add(maleRadioButton);
        panel.add(femaleRadioButton);
        panel.add(new JLabel("Courses: "));
        panel.add(mathCheckBox);
        panel.add(scienceCheckBox);
        panel.add(englishCheckBox);
        panel.add(submitButton);

        add(panel, BorderLayout.NORTH);
        add(infoTextArea, BorderLayout.CENTER);
    }

    private void displayStudentInfo() {
        String name = nameTextField.getText();
        String gender = maleRadioButton.isSelected() ? "Male" : "Female";
        String courses = "";
        if (mathCheckBox.isSelected()) {
            courses += "Math, ";
        }
        if (scienceCheckBox.isSelected()) {
            courses += "Science, ";
        }
        if (englishCheckBox.isSelected()) {
            courses += "English";
        }

        String info = "Name: " + name + "\nGender: " + gender + "\nCourses: " + courses;
        infoTextArea.setText(info);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                StudentInfoApp app = new StudentInfoApp();
                app.setVisible(true);
            }
        });
    }
}
